package com.findme.fecedetection.utlis.extend

import android.app.Activity
import android.text.TextUtils
import com.findme.fecedetection.utlis.ToastUtils.showToast
import com.tanguy.user.App.Companion.app

/**
 * Created by dab on 2017/11/3 0003 08:56
 * 检测是否符合规矩
 */
/**
 * 检测手机号
 *
 * @param phone
 * @return
 */
fun checkPhoneNumber(phone: String): Boolean {
    if (TextUtils.isEmpty(phone)) {
        showToast(app, "请输入手机号")
        return false
    }
    if (phone.length != 11) {
        showToast(app, "请输入11位的手机号")
        return false
    }
//    if (!Utils.isPhoneNumber(phone)) {
//        showToast(app, "手机号不合法")
//        return false
//    }
    return true
}

/**
 * 检测密码
 *
 * @param password
 * @return
 */
fun checkPassword(password: String): Boolean {
    if (TextUtils.isEmpty(password)) {
        showToast(app, "请输入密码")
        return false
    }
    val length = password.length
    if (length < 6 || length > 18) {
        showToast(app, "密码的长度在6到20位之间")
        return false
    }
    return true
}

/**
 * 检测两个密码是否一样
 *
 * @param password
 * @return
 */
fun Activity.checkPasswordAlike(password: String, newPassword: String): Boolean {
    if (!checkPassword(password)) {
        return false
    }
    if (TextUtils.isEmpty(newPassword)) {
        showToast("请输入确认密码")
        return false
    }
    if (password != newPassword) {
        showToast("两次密码不一致")
        return false
    }
    return true
}

/**
 * 检测验证码
 *
 * @param captcha
 * @return
 */
fun checkCaptcha(captcha: String): Boolean {
    if (TextUtils.isEmpty(captcha)) {
        showToast(app, "请输入验证码")
        return false
    }
    if (captcha.length != 4) {
        showToast(app, "请输入4位数的验证码")
        return false
    }
    return true
}



